﻿using Direct.IDAL.Manager.Money;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DirectSell.Model.Manager;
using System.Collections;
using DirectSell.Model.Money;

namespace DirectSell.BLL.Manager.Money
{
    /// <summary>
    /// 提现审核服务层
    /// </summary>
    public class RealMoneyAuditService:ManagerService
    {
        #region 日志记录
        /// <summary>
        /// 日志记录文件名
        /// </summary>
        protected override string LogFile
        {
            get
            {
                return "提现审核";
            }
        }
        #endregion

        #region 构造函数
        /// <summary>
        /// 提现审核仓储接口
        /// </summary>
        protected IRealMoneyAuditRepository _repository { get; set; }
        public RealMoneyAuditService(IRealMoneyAuditRepository repository)
        {
            this._repository = repository;
        }
        #endregion

        #region 操作入口
        /// <summary>
        /// 操作入口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param"></param>
        /// <returns></returns>
        protected async override Task<ManagerRespCode> OperationAsync<T>(T param)
        {
            var model = param as RealMoneyAudit;
            if (model == null)
            {
                return ManagerRespCode.传入参数不正确;
            }
            await LogAsync(model);

            Hashtable hstable = new Hashtable();

            _repository.Audit(model.Id, model.Type,ref hstable);

            if (model.Type == 1)
            {
                _repository.Refund(model.UserCode, model.Amount, ref hstable);

                Consumption con = new Consumption()
                {
                    Affair = "拒绝提现退款",
                    Amout = model.Amount,
                    CreateDate = DateTime.Now,
                    LogType = 1,
                    Operator = model.UserCode,
                    Relevant = model.UserCode
                };
            }
            if (!_repository.CommitDapperTranLock(hstable))
            {
                return ManagerRespCode.失败;
            }
            return ManagerRespCode.成功;
        }
        #endregion
    }
}
